<!--
 * @Author: alan_mf
 * @Date: 2023-05-12 15:44:57
 * @LastEditors: alan_mf
 * @LastEditTime: 2024-08-19 11:16:24
 * @FilePath: /oa-project/src/views/userSetup/systemSetup/index.vue
 * @Description: 
 * 
-->
<script setup lang="ts">
import { reactive, ref, onMounted } from "vue";
import { systemSettings, systemSettingsEdit } from "@/api/settings";
import * as CryptoJS from "crypto-js";
import { message } from "@/utils/message";
import { getSessionKey } from "@/utils/auth";

const formIs = ref({
  quota: "",
  money: "",
  admin_nick: "",
  ping: "",
  month: "",
  month_percent: "",
  time_limit: "",
  subject: "",
  square: "",
  vip_gou: "",
  vip_shou: "",
  day_shou: "",
  day_fu: "",
  chou: "",
  drawstatus: "",
  drawnum: ""
});
const roleUser = ref("");
const show = ref(false);
const acValue = 2;
const inValue = 1;
const formLabelWidth = "150px";
defineOptions({
  // name 作为一种规范最好必须写上并且和路由的name保持一致
  name: "SystemSetup"
});
async function handleUser(roleId) {
  roleUser.value = roleId;
  const role = {
    event: "event"
  };
  // 将formIsRef.value对象转换为JSON字符串
  const formIsRefStr = JSON.stringify(role);

  // 对JSON字符串进行Base64加密
  const encryptedFormIsRef = CryptoJS.enc.Base64.stringify(
    CryptoJS.enc.Utf8.parse(formIsRefStr)
  );
  const encryptedFormIsRefValue = {
    value: encryptedFormIsRef
  };
  const res = await systemSettings(encryptedFormIsRefValue);
  if (res.code === 200) {
    res.data.drawstatus = res.data.drawstatus.toString();
    formIs.value = res.data;
    show.value = true;
  }
}
//提交修改
async function handleSubmit() {
  // 将formIsRef.value对象转换为JSON字符串
  const formIsRefStr = JSON.stringify(formIs.value);
  // 对JSON字符串进行Base64加密
  const encryptedFormIsRef = CryptoJS.enc.Base64.stringify(
    CryptoJS.enc.Utf8.parse(formIsRefStr)
  );
  const encryptedFormIsRefValue = {
    value: encryptedFormIsRef
  };
  console.log(encryptedFormIsRefValue);
  const res = await systemSettingsEdit(encryptedFormIsRefValue);
  if (res.code === 200) {
    message("修改成功", { type: "success" });
  }
}
onMounted(() => {
  const roleId = getSessionKey().role_id;
  handleUser(roleId);
});
</script>

<template>
  <div id="mian" v-if="show">
    <el-form>
      <el-form-item label="抽奖开关" :label-width="formLabelWidth">
        <el-switch
          v-model="formIs.drawstatus"
          active-value="1"
          inactive-value="0"
        />
      </el-form-item>
      <el-form-item label="红包数量" :label-width="formLabelWidth">
        <el-input
          size="large"
          v-model="formIs.drawnum"
          autocomplete="off"
          style="width: 100px"
        />
      </el-form-item>
      <el-form-item label="提现手续费" :label-width="formLabelWidth">
        <el-input
          size="large"
          v-model="formIs.quota"
          autocomplete="off"
          style="width: 100px"
        />
        %
      </el-form-item>
      <el-form-item label="可提现金额(最低)" :label-width="formLabelWidth">
        <el-input
          size="large"
          v-model="formIs.money"
          autocomplete="off"
          style="width: 100px"
        />元
      </el-form-item>
      <el-form-item label="级差平级比例" :label-width="formLabelWidth">
        <el-input
          size="large"
          v-model="formIs.ping"
          autocomplete="off"
          style="width: 100px"
        />%
      </el-form-item>
      <el-form-item label="每题奖励" :label-width="formLabelWidth">
        <el-input
          size="large"
          v-model="formIs.subject"
          autocomplete="off"
          style="width: 100px"
        />云值
      </el-form-item>
      <div style="display: flex">
        <el-form-item label="代理商月收入" :label-width="formLabelWidth">
          <el-input
            size="large"
            v-model="formIs.month"
            autocomplete="off"
            style="width: 100px"
          />
          以上部分 , 自动取
          <el-input
            size="large"
            v-model="formIs.month_percent"
            autocomplete="off"
            style="width: 100px"
          />% 进入复消账户.
        </el-form-item>
      </div>
      <div style="display: flex">
        <el-form-item label="用户购买奖励" :label-width="formLabelWidth">
          <el-input
            size="large"
            v-model="formIs.vip_gou"
            autocomplete="off"
            style="width: 100px"
          />%云值
        </el-form-item>
        <el-form-item label="收益奖励" :label-width="80">
          <el-input
            size="large"
            v-model="formIs.vip_shou"
            autocomplete="off"
            style="width: 100px"
          />%云值
        </el-form-item>
      </div>
      <div style="display: flex">
        <el-form-item label="日分红  首单比例" :label-width="formLabelWidth">
          <el-input
            size="large"
            v-model="formIs.day_shou"
            autocomplete="off"
            style="width: 100px"
          />%
        </el-form-item>
        <el-form-item label="复购比例" :label-width="80">
          <el-input
            size="large"
            v-model="formIs.day_fu"
            autocomplete="off"
            style="width: 100px"
          />%
        </el-form-item>
      </div>
    </el-form>
    <span style="margin-right: 80px">
      <el-button type="primary" @click="handleSubmit()" v-auth="'set_sumbit'">
        提交
      </el-button>
    </span>
  </div>
</template>
